package org.goldfish.library_system.service;

import org.goldfish.library_system.entity.Reader;
import org.goldfish.library_system.repos.ReaderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class ReaderService {
    @Autowired
    private ReaderRepository readerRepository;

    // 获取所有读者
    public List<Reader> findAllReaders() {
        return readerRepository.findAll();
    }

    // 根据 ID 获取读者
    public Optional<Reader> findReaderById(Long id) {
        return readerRepository.findById(id);
    }

    // 添加或更新读者
    public Reader saveReader(Reader reader) {
        return readerRepository.save(reader);
    }

    // 删除读者
    public void deleteReader(Long id) {
        readerRepository.deleteById(id);
    }
}